package com.pojoin.cms.springTest;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 测试的时候如果需要调用Spring上下文，使用此类，发布时如果需要调用Spring上下文使用SpringContext类
 * 
 * @author ZYT
 * 
 */
public class SpringInit {

	private static ApplicationContext acx = null;

	private static Object obj = new Object();

	private static ApplicationContext getSpringContext() {
		synchronized (obj) {
			if (acx == null) {
				acx = new ClassPathXmlApplicationContext(new String[] {
						"applicationcontext.xml", "applicationcontext-action.xml" , "testcontext.xml" });
			}
			return acx;
		}
	}

	/**
	 * 测试的时候如果需要调用Spring bean，使用此方法，发布时如果需要调用Spring
	 * bean上下文使用SpringContext.getBean(beanName);
	 * 
	 * @param beanName
	 * @return
	 */
	public static Object getBean(String beanName) {
		return getSpringContext().getBean(beanName);
	}

}
